﻿/*
 * 
 * V2版参数文件上传. 09-11-22 szj
 * 
 * 
 * 
 * 
 * 
 * 
 * */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using EQT.Bll;
using EQT.Model;
using EQT.Dal;
using DevFuture.Common;

/// <summary>
/// UploadParameterFile 的摘要说明
/// </summary>
public class UploadParameterFile : IUploadFile
{
    public UploadParameterFile()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    //使用V2版
    //private DaContract dacontract = DevFuture.Common.WorkContext.AppCtx.GetObject("DaContract") as DaContract;
    private DaProductCheckContract dacontract = WorkContext.AppCtx.GetObject("DaProductCheckContract") as DaProductCheckContract;
    //private DaSampleParameter dasp = DevFuture.Common.WorkContext.AppCtx.GetObject("DaSampleParameter") as DaSampleParameter;

    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {
        #region 为了合同而上传参数文件

        string report_id = nvc["report_id"];//获取合同ID号
        if (String.IsNullOrEmpty(report_id) || report_id.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【合同编号】", up.Response);
        }
        else
        {
            up.SetConfigValue("REPORT_ID", report_id);
            
            //MoContract mo = new MoContract();
            MoProductCheckContract mo = new MoProductCheckContract();
            mo.ReportId = report_id;
            dacontract.GetEntityEx(ref mo);
            up.SetPageTitle(String.Format("为客户【{0}】合同【{1}】上传参数文件：",
                mo.CorpName, report_id));

        }
        #endregion
    }

    public int Upload1(IUploadPage up, MoTfiles file, string opter_id)
    {
        #region 参数文件上传
 
        //MoSampleParameter mosp = new MoSampleParameter();
        //mosp.SampleId = SequenceKeys.GenerateSampleID();
        //mosp.ReportId = up.GetConfigValue("REPORT_ID").ToString();
        //mosp.RegDate = DateTime.Today;
        //mosp.RefParFile = file.FileId;

        try
        {
            return dacontract.AddProductParameterFile(file, up.GetConfigValue("REPORT_ID").ToString(), WorkContext.AppCtx.GetObject("DaTfiles") as DaTfiles);
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("为合同添加参数文件上传失败!", de);
            Utility.SiteError("为合同添加参数文件上传失败!" + de.Message, up.Response);
            return -1;
        }
      
        #endregion
    }

    public int UploadedMuliti(IUploadPage up, List<MoTfiles> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        return String.Format("PCAInfo.aspx.aspx?report_id={0}", up.GetConfigValue("REPORT_ID"));
    }

    #endregion
}
